<template>
  <div class="ticketInfoBox">
    <div class="ticket_Header" @click="boxBack">
      <span> <svg-icon icon-class="jiantouZuo" /> 任务详情 </span>
    </div>

    <div class="ticket_Body">
      <!-- 排期执行 -->
      <div class="ticket_card">
        <div class="card_title">排期执行</div>
        <div class="card_Body card_ticket">
          <div class="ticket_content">
            <!-- 类型 -->
            <div class="ticket__aim">
              <svg-icon
                icon-class="new_aim_paizhao"
                v-if="ticketInfoData.aim == 1"
              />
              <svg-icon
                icon-class="new_aim_zhibo"
                v-else-if="ticketInfoData.aim == 2"
              />
              <svg-icon
                icon-class="new_aim_all"
                v-else-if="ticketInfoData.aim == 3"
              />
              <svg-icon
                icon-class="new_aim_720"
                v-else-if="ticketInfoData.aim == 4"
              />
              <svg-icon
                icon-class="new_aim_2D"
                v-else-if="ticketInfoData.aim == 5"
              />
              <svg-icon
                icon-class="new_aim_3D"
                v-else-if="ticketInfoData.aim == 6"
              />
            </div>

            <!-- 地形 -->
            <div class="ticket_mark" v-if="ticketInfoData.plot">
              <svg-icon
                icon-class="new_mark_point"
                v-if="ticketInfoData.plot.plot_shape == 1"
              />
              <svg-icon
                icon-class="new_mark_line"
                v-if="ticketInfoData.plot.plot_shape == 2"
              />
              <svg-icon
                icon-class="new_mark_polygon"
                v-if="ticketInfoData.plot.plot_shape == 3"
              />
            </div>

            <!-- 航线名称 -->
            <div class="ticket_ticketName">
              {{ ticketInfoData.ticket_name }}
            </div>
          </div>

          <!-- 班次 -->
          <div class="ticket_content">
            <div><svg-icon icon-class="tree"></svg-icon></div>

            <div class="ticket_quantity">
              轮次
              <span class="ticket_num">
                {{
                  (ticketInfoData.execute_detail &&
                    ticketInfoData.execute_detail.ing_task) ||
                  0
                }}
                /
                {{
                  (ticketInfoData.execute_detail &&
                    ticketInfoData.execute_detail.total_task) ||
                  0
                }}
              </span>
            </div>

            <div class="ticket_quantity">
              架次
              <span class="ticket_num">
                {{
                  (ticketInfoData.execute_detail &&
                    ticketInfoData.execute_detail.ing_sortie) ||
                  0
                }}
                /
                {{
                  (ticketInfoData.execute_detail &&
                    ticketInfoData.execute_detail.total_sortie) ||
                  0
                }}
              </span>
            </div>
          </div>

          <!-- 排期 -->
          <div class="ticket_content">
            <div><svg-icon icon-class="form" /></div>
            <div class="ticket_schedule">
              {{ ticketInfoData.schedule_detail }}
            </div>
          </div>

          <!-- 状态 -->
          <div class="ticket_content">
            <!-- 排期状态 -->
            <div class="ticket_tag">
              <span
                class="tag_box tag0BW"
                v-if="ticketInfoData.schedule_type == 1"
              >
                已排期
              </span>
              <span
                class="tag_box tag0GW"
                v-else-if="ticketInfoData.schedule_type == 0"
              >
                未排期
              </span>
            </div>
            <!-- 任务状态 -->
            <div class="ticket_tag">
              <el-tooltip
                class="item"
                effect="dark"
                :content="
                  ticketInfoData.ticket_state
                    ? ticketInfoData.ticket_state
                    : '未知'
                "
                :disabled="true"
                placement="top"
                :open-delay="400"
              >
                <span class="tag_box tag3GG">
                  {{ ticketInfoData.ticket_state || "未知" }}
                </span>
              </el-tooltip>
            </div>
          </div>

          <!-- 轮次 -->
          <div class="ticket_content">
            <template v-for="(task, index) in ticketInfoData.tasks">
              <div
                v-if="task.flight_records.length > 0"
                class="ticket_rounds"
                :class="{
                  taskSelected:
                    taskSelect && taskSelect.task_id == task.task_id,
                }"
                :key="index"
                @click="selectTask(task)"
              >
                <div class="round">巡检轮次{{ task.round }}</div>
              </div>
            </template>
          </div>

          <!-- 照片 -->
          <div class="ticket_content" v-if="taskSelect && !!taskSelect.task_id">
            <div
              class="ticket_photos"
              v-for="(item, index) in taskSelect.flight_records"
              :key="index"
            >
              <div
                class="photo_pic"
                @click="selectLine(item, index)"
                :class="{
                  selectLinePhoto:
                    lineSelect.flight_record_code == item.flight_record_code,
                }"
              >
                <div class="pic_svg">
                  <svg-icon
                    icon-class="new_eye_open"
                    class="eyeOpen"
                    @click.stop="closeLine(item)"
                    v-if="item.showLine"
                  ></svg-icon>
                  <svg-icon
                    icon-class="new_eye_close"
                    class="eyeClose"
                    @click.stop="openLine(item)"
                    v-else
                  ></svg-icon>
                </div>
                <div v-if="taskSelect.flight_records.length > 1">
                  <div class="pic_num">
                    {{ index + 1 }}
                  </div>
                  <div class="pic_block"></div>
                </div>
                <img
                  v-if="item.photos"
                  :src="urlAddToken(item.photos[0].photo_file_url)"
                  alt=""
                />
                <div class="pic_bottom">
                  <div class="bottom_content">
                    <svg-icon icon-class="tag" /> 标记 {{ item.marks }}
                  </div>
                  <div class="bottom_content">
                    <svg-icon icon-class="viewPhotos" /> 照片
                    {{ item.photo_count }}
                  </div>
                </div>
              </div>
              <div class="photo_time">
                {{ item.flight_date | flightDateFilter }}
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 巡检地块 -->
      <div class="ticket_card" v-if="ticketInfoData.plot">
        <div class="card_title">巡检地块</div>
        <div class="card_Body">
          <!-- 形状 -->
          <div class="card_info_content">
            <div class="content_title">形状 :</div>
            <div class="content_body">
              {{ ticketInfoData.plot.plot_shape | plotShapeFilter }}
            </div>
          </div>

          <!-- 半径 -->
          <div class="card_info_content">
            <div class="content_title">半径 :</div>
            <div class="content_body">
              {{
                ticketInfoData.plot.radius
                  ? ticketInfoData.plot.radius + "m"
                  : "--"
              }}
            </div>
          </div>

          <!-- 面积 -->
          <!-- <div class="card_info_content">
            <div class="content_title">面积 :</div>
            <div class="content_body">
              {{
                ticketInfoData.plot.area
                  ? ticketInfoData.plot.area + "km²"
                  : "--"
              }}
            </div>
          </div> -->

          <!-- 中心经度 -->
          <div class="card_info_content">
            <div class="content_title">中心经度 :</div>
            <div class="content_body">
              {{ ticketInfoData.plot.position[0] || "--" }}
            </div>
          </div>

          <!-- 中心纬度 -->
          <div class="card_info_content">
            <div class="content_title">中心纬度 :</div>
            <div class="content_body">
              {{ ticketInfoData.plot.position[1] || "--" }}
            </div>
          </div>

          <!-- 位置详情 -->
          <div class="card_info_content">
            <div class="content_title">位置详情 :</div>
            <div class="content_body">
              {{ ticketInfoData.plot.address || "--" }}
            </div>
          </div>
        </div>
      </div>

      <!-- 巡检用途 -->
      <div class="ticket_card">
        <div class="card_title">巡检用途</div>
        <div class="card_Body">
          <!-- 用途 -->
          <div class="card_info_content">
            <div class="content_title">用途 :</div>
            <div class="content_body">
              {{ ticketInfoData.aim | aimFilter }}
            </div>
          </div>

          <!-- 备注 -->
          <div class="card_info_content">
            <div class="content_title">备注 :</div>
            <div class="content_body">
              {{ ticketInfoData.description || "--" }}
            </div>
          </div>
        </div>
      </div>

      <!-- 提交信息 -->
      <div class="ticket_card">
        <div class="card_title">提交信息</div>
        <div class="card_Body">
          <!-- 提交人 -->
          <div class="card_info_content">
            <div class="content_title">提交人 :</div>
            <div class="content_body">
              {{ ticketInfoData.commit_person }}
            </div>
          </div>

          <!-- 提交部门 -->
          <div class="card_info_content">
            <div class="content_title">提交部门 :</div>
            <div class="content_body">
              {{ ticketInfoData.commit_org_name }}
            </div>
          </div>

          <!-- 紧急度 -->
          <div class="card_info_content">
            <div class="content_title">紧急度 :</div>
            <div class="content_body">
              {{ ticketInfoData.urgency | urgencyFilter }}
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="ticket_footer">
      <el-button type="primary" @click="boxBack">确定</el-button>
      <el-button
        type="warning"
        @click="resubmit"
        v-if="ticketInfoData.ticket_state == '已完成'"
      >
        再次提交
      </el-button>
      <el-button
        type="danger"
        @click="ticketDel"
        v-if="order_delete_auth && ticketInfoData.ticket_state == '待审核'"
      >
        删除
      </el-button>
    </div>
  </div>
</template>

<script>
import moment from "moment";
import { delTicket } from "@/api/view5";
import { addUrlToken } from '@/utils/allTool';

export default {
  name: "TicketInfo",
  props: {
    // 权限
    userAuthor: {
      default() {
        return {};
      },
    },
    // 选中任务
    ticketInfoData: {
      default() {
        return {};
      },
    },
    // 是否再次提交
    ifAddAgain: {
      default() {
        return false;
      },
    },
  },
  filters: {
    // 地块类型
    plotShapeFilter(val) {
      switch (val) {
        case 1:
          return "兴趣点";
        case 2:
          return "带状";
        case 3:
          return "面状";
        case 4:
          return "全覆盖";
        default:
          return "未知";
      }
    },

    // 用途
    aimFilter(val) {
      switch (val) {
        case 1:
          return "拍照";
        case 2:
          return "直播";
        case 3:
          return "全覆盖";
        case 4:
          return "全景";
        case 5:
          return "正射";
        case 6:
          return "三维";
        default:
          return "未知";
      }
    },

    // 紧急度
    urgencyFilter(val) {
      switch (val) {
        case 1:
          return "紧急";
        case 2:
          return "一般";
        case 3:
          return "不紧急";
        default:
          return "未知";
      }
    },

    flightDateFilter(val) {
      return moment(val).format("YYYY年MM月DD日");
    },
  },
  components: {},
  data() {
    return {
      // 选中轮次
      taskSelect: {},
      lineSelect: {},

      selectPhoto: null, // 选中的图片
      photoIndex: "", // 选中图片的序号
      photoFirst: false, // 第一次点击图片
    };
  },
  computed: {
    // 权限
    // 指点任务 删除任务
    order_delete_auth() {
      return this.userAuthor?.order?.delete?.have_auth;
    },
  },
  mounted() {
    this.initData();
  },
  methods: {
    urlAddToken(url){
      return addUrlToken(url)
    },
    initData() {
      console.log("ticketInfoData", this.ticketInfoData);

      this.$emit("drawPlot");
      if (this.ticketInfoData.tasks.length > 0) {
        this.selectTask(this.ticketInfoData.tasks[0]);
      }
    },
    // 选中轮次
    selectTask(val) {
      console.log("task", val);
      if (val.task_id == this.taskSelect.task_id) {
        this.$parent.openTask(val);
        return;
      } else {
        // 清空图层
        airlineMapLayer && CesiumUtil.LayerRemoveAll(airlineMapLayer);
      }

      this.taskSelect = val;
      this.taskSelect.flight_records.map((item, index) => {
        item.showLine = true;
      });
      this.$emit("drawSeeAirline", val);
    },

    // 查找航线
    findLine(code) {
      console.log(this.taskSelect.flight_records);
      let findLine = this.taskSelect.flight_records.find((line) => {
        return line.flight_record_code == code;
      });
      console.log("findLine", findLine);
      if (findLine && findLine.showLine) {
        this.selectLine(findLine);
        return true;
      } else {
        return false;
      }
    },
    // 选中航线
    selectLine(val) {
      console.log("line", val);
      this.lineSelect = val;
      this.$emit("selectAirline", val.flight_record_code);
    },
    // 关闭航线
    closeLine(val) {
      console.log("closeLine", val);
      val.showLine = false;
      this.$emit("changeAirlineSee", val.flight_record_code, false);
      this.$forceUpdate();
    },
    // 显示航线
    openLine(val) {
      console.log("openLine", val);
      val.showLine = true;
      this.$emit("changeAirlineSee", val.flight_record_code, true);
      this.$forceUpdate();
    },

    // 返回列表
    boxBack() {
      this.$emit("boxStatusChange", 1);
    },
    // 再次提交
    resubmit() {
      this.$confirm("是否再次提交", "提示", {
        confirmButtonText: "提交",
        cancelButtonText: "取消",
      })
        .then((res1) => {
          // this.$message.warning("再次提交");
          console.log("提交");

          this.$parent.ifAddAgain = true;
          this.$emit("boxStatusChange", 2);
        })
        .catch((err) => {});
    },
    // 再次提交
    ticketDel() {
      // this.$message.warning("删除任务");
      this.$confirm("是否删除任务", "提示", {
        confirmButtonText: "删除",
        confirmButtonClass: "confirmDelButton",
        cancelButtonText: "取消",
      })
        .then((res1) => {
          delTicket({ ticket_id: this.ticketInfoData.id }).then((res) => {
            if (res.msg === "ok") {
              this.$message.success("删除成功");
              this.$emit("boxStatusChange", 1);
              this.$parent.$refs.TicketList.getTicketList();
            } else {
              this.$message.warning(res.msg);
            }
          });
        })
        .catch((err) => {});
    },
  },
  watch: {},
};
</script>

<style lang="scss" scoped>
* {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
$color1: #18abf3;

.ticketInfoBox {
  height: 100%;
  display: flex;
  flex-direction: column;

  .ticket_Header {
    background-image: url("~@/assets/box_title_back1.png");
    background-size: 100% 100%;
    text-align: start;
    width: 100%;
    height: vh(30);
    line-height: vh(30);
    margin: vh(5) auto;
    ticket-height: vh(30);
    font-size: 14px;
    color: white;
    padding: 0px 10px;

    display: flex;
    justify-content: space-between;
    align-items: center;

    cursor: pointer;
  }
  .ticket_Body {
    flex: 1;
    // max-height: vh(850);
    padding: 5px;
    overflow: auto;
    .ticket_card {
      background-color: #ffffff1a;
      margin-bottom: 5px;
      border-radius: 5px;
      .card_title {
        color: $color1;
        font-size: 12px;
        padding: 5px 15px;
        text-align: start;
        border-bottom: 1px solid $color1;
      }
      .card_Body {
        padding: 5px 15px;
        .card_info_content {
          padding: 5px 0;
          display: flex;
          font-size: 12px;
          .content_title {
            width: 70px;
            text-align: start;
          }
          .content_body {
            text-align: start;
            flex: 1;
          }
        }
      }
      .card_ticket {
        .ticket_content {
          display: flex;
          flex-wrap: nowrap;
          overflow-x: auto;
          font-size: 12px;
          padding: 4px 0;
          .ticket__aim {
            margin-right: 5px;
          }
          .ticket_mark {
            margin-right: 5px;
          }
          .ticket_ticketName {
          }
          .ticket_quantity {
            margin-left: 5px;
            .ticket_num {
              margin-left: 2px;
              background-color: #575858;
              padding: 2px;
              border-radius: 3px;
            }
          }
          .ticket_schedule {
            margin-left: 5px;
          }
          .ticket_tag {
            font-size: 10px;
            .tag_box {
              padding: 2px;
              border-radius: 0 3px 3px 0;
              height: 20px;
              position: relative;
              margin-left: 10px;
              &::after {
                content: "";
                position: absolute;
                left: -3px;
                top: 6px;
                width: 4px;
                height: 4px;
                border-radius: 50%;
              }
              &::before {
                content: "";
                position: absolute;
                left: -7px;
                top: 0;
                border-right-width: 7px;
                border-left-width: 0px;
                border-top-width: 8px;
                border-bottom-width: 7px;
                border-color: #00000000;
                border-style: solid;
              }

              &.tag0BW {
                background-color: #1c5989;
                color: #fff;
                &::before {
                  border-right-color: #1c5989;
                }
                &::after {
                  background-color: #fff;
                }
              }
              &.tag0GW {
                background-color: #b5b5b5;
                color: #fff;
                &::before {
                  border-right-color: #b5b5b5;
                }
                &::after {
                  background-color: #fff;
                }
              }
              &.tag1GW {
                background-color: #5b676a;
                color: #fff;
                &::before {
                  border-right-color: #5b676a;
                }
                &::after {
                  background-color: #fff;
                }
              }
              &.tag2YW {
                background-color: #6b6c2d;
                color: #fff;
                &::before {
                  border-right-color: #6b6c2d;
                }
                &::after {
                  background-color: #fff;
                }
              }
              &.tag3GG {
                background-color: #2a8237;
                color: #45d943;
                &::before {
                  border-right-color: #2a8237;
                }
                &::after {
                  background-color: #45d943;
                }
              }
            }
          }
          .ticket_rounds {
            margin-top: 5px;
            margin-right: 5px;
            background-color: #555;
            padding: 2px;
            border-radius: 5px;
            border: 1px solid #555;
            cursor: pointer;
            &:hover {
              border: 1px solid #1f84b4;
            }
            &.taskSelected {
              border: 1px solid #1f84b4;
            }
            .round {
              width: 80px;
            }
          }
          .ticket_photos {
            margin-top: 5px;
            margin-right: 5px;
            padding: 2px;
            border-radius: 5px;
            cursor: pointer;
            .photo_pic {
              width: 110px;
              height: 80px;
              background-color: #ffffff50;
              border-radius: 3px;
              position: relative;
              border: 1px solid #00000000;
              &:hover {
                border: 1px solid #00f;
              }
              &.selectLinePhoto {
                border: 1px solid #00f;
              }
              img {
                width: 100%;
                height: 100%;
              }
              .pic_num {
                position: absolute;
                top: 2px;
                left: 4px;
                z-index: 10;
              }
              .pic_block {
                z-index: 9;
                position: absolute;
                left: 0;
                top: 0;
                border: 14px solid #0951da;
                border-bottom-color: #00000000;
                border-right-color: #00000000;
              }
              .pic_svg {
                position: absolute;
                top: 2px;
                right: 5px;
                font-size: vw(20);
                .eyeOpen {
                  color: #0951da;
                }
                .eyeClose {
                  color: #000;
                }
              }
              .pic_bottom {
                position: absolute;
                bottom: 0;
                display: flex;
                background-color: #373737;
                width: 100%;
                padding: 2px;
                font-size: 9px;
                .bottom_content {
                  flex: 1;
                  text-align: center;
                }
              }
            }
            .photo_time {
              margin-top: 5px;
              font-size: 10px;
              color: #ccc;
            }
          }
        }
      }
    }
  }
  .ticket_footer {
    display: flex;
    .el-button {
      flex: 1;
    }
  }
}
</style>
